# import necessary packages
import cv2 as cv
import numpy as np
import argparse

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="The Path to image")
args = vars(ap.parse_args())

# load the image and disply it
image = cv.imread(args["image"])
cv.imshow("Original", image)

# Masking allows us to focus only on parts of an image that interest us.
# A mask is the same size as our image,but has only two pixel values,
# 0 and 255.Pixels with a value of 0 are ignored in the original image,
# and mask pixels with a value of 255 are allowed to be kept. For exaple,
# let's construct a rectangular mask that displays only the person in
# the image
mask = np.zeros(image.shape[:2], dtype="uint8")
cv.rectangle(mask, (0, 90), (290, 450), 255, -1)
cv.imshow("Mask",mask)

# Apply our mask -- notice how only the person in the image is cropped out
masked = cv.bitwise_and(image,image,mask=mask)
cv.imshow("Mask Applied to Image",masked)
cv.waitKey(0)

# Now,let's make a circular with a radius of 100 pixels and apply the
# mask again
mask = np.zeros(image.shape[:2],dtype="uint8")
cv.circle(mask,(145,200),100,255,-1)
masked = cv.bitwise_and(image,image,mask=mask)
cv.imshow("Mask",mask)
cv.imshow("Mask Applied to Image",masked)
cv.waitKey(0)